//
//  OPPageContainer.m
//  OPFramework
//
//  Created by malcom on 7/21/08.
//  Copyright 2008 malcom-mac software. All rights reserved.
//

#import "OPPageContainer.h"


@implementation OPPageContainer

@synthesize p_pagesContainer;
@synthesize p_totalPages;
@synthesize p_totalElements;

- (id) init
{
	self = [super init];
	if (self != nil) {
		p_pagesContainer = [[NSMutableDictionary alloc] init];
		p_totalElements = 0;
		p_totalPages = 0;
	}
	return self;
}

- (void) clear {
	[p_pagesContainer release];
	p_pagesContainer = [[NSMutableDictionary alloc] init];
	p_totalElements = -1;
	p_totalPages = -1;
}

- (NSArray *) getPageAtIndex:(NSNumber *) _pg {
	return [p_pagesContainer objectForKey: _pg];
}

- (void) addPage:(NSArray *) _page atIndex:(NSNumber *) _num {
	if (_page != nil) [p_pagesContainer setObject: _page forKey: _num];
}

- (int) realElements {
	int t = 0;
	for (NSArray *cpage in [p_pagesContainer allValues])
		t+=[cpage count];
	return t;
}

- (NSArray *) getFlatElements {
	NSMutableArray *list = [[NSMutableArray alloc] init];
	for (NSArray *cPage in [p_pagesContainer allValues])
		[list addObjectsFromArray: cPage];
	return [list autorelease];
}

- (void) removeElementFromPages:(id) _element {
	for (NSMutableArray *cPage in [p_pagesContainer allValues])
		[cPage removeObject: _element];
}

@end
